/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slt.Model;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Robbert Stevens
 */
public class User {    
    private long userId;
    private String username;
     private String name;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    private String address;
    private String zipcode;
    private String city;
    private String country;
    private String emailaddress;
    private String password;
    private String phonenumber;
    private Date dateOfBirth;
    private Map<String, String> errors;
    //picture
    
    public User() {
        this.errors = new HashMap<String, String>();
    }
    
    public User(long userId) {
        this();
        
        this.userId = userId;
    }

    /**
     * @return the userId
     */
    public long getUserId() {
        return userId;
    }

    /**
     * @param userId the userId to set
     */
    public void setUserId(long userId) {
        this.userId = userId;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        if(name.isEmpty()) {
            errors.put("name", "Name cannot be empty.");
        } else {
            this.name = name.trim();
        }
    }

    /**
     * @return the address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(String address) {
        if(address.isEmpty()) {
            errors.put("address", "Address cannot be empty.");
        } else {
            this.address = address.trim();
        }
    }

    /**
     * @return the zipcode
     */
    public String getZipcode() {
        return zipcode;
    }

    /**
     * @param zipcode the zipcode to set
     */
    public void setZipcode(String zipcode) {
        if(zipcode.isEmpty()) {
            errors.put("zipcode", "Zipcode cannot be empty.");
        } else {
            this.zipcode = zipcode.trim();
        }
    }

    /**
     * @return the city
     */
    public String getCity() {
        return city;
    }

    /**
     * @param city the city to set
     */
    public void setCity(String city) {
        if(city.isEmpty()) {
            errors.put("city", "City cannot be empty.");
        } else {
            this.city = city.trim();
        }
    }

    /**
     * @return the country
     */
    public String getCountry() {
        return country;
    }

    /**
     * @param country the country to set
     */
    public void setCountry(String country) {
        if(country.isEmpty()) {
            errors.put("country", "Country cannot be empty.");
        } else {
            this.country = country.trim();
        }
    }

    /**
     * @return the emailaddress
     */
    public String getEmailaddress() {
        return emailaddress;
    }

    /**
     * @param emailaddress the emailaddress to set
     */
    public void setEmailaddress(String emailaddress) {
        if(!errors.containsKey("emailaddress") &&
            emailaddress == null || emailaddress.isEmpty()) {
            errors.put("emailaddress", "Email address cannot be empty.");
        }
        this.emailaddress = emailaddress.trim().toLowerCase();
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        if(!errors.containsKey("passwordMatch")) {
            if(password == null || password.length() < 7) {
                errors.put("password", "Password cannot be shorter than 7 characters.");
            }
        }
        this.password = password.trim();
    }
    
    public void setPassword(String password1, String password2) {
        if(!password1.matches(password2)) {
            errors.put("passwordMatch", "Both passwords must match.");
        } else {
            setPassword(password1);
        }
    }

    /**
     * @return the phonenumber
     */
    public String getPhonenumber() {
        return phonenumber;
    }

    /**
     * @param phonenumber the phonenumber to set
     */
    public void setPhonenumber(String phonenumber) {
        if(phonenumber.isEmpty()) {
            errors.put("phonenumber", "Phonenumber cannot be empty.");
        } else {
            this.phonenumber = phonenumber.trim();
        }
    }

    /**
     * @return the dateOfBirth
     */
    public Date getDateOfBirth() {
        return dateOfBirth;
    }

    /**
     * @param dateOfBirth the dateOfBirth to set
     */
    public void setDateOfBirth(Date dateOfBirth) {
        if(dateOfBirth == null) {
            errors.put("dateofbirth", "Date of birth cannot be empty.");
        } else {
            this.dateOfBirth = dateOfBirth;
        }
    }
    /**
     * @return the errors
     */
    public Map<String, String> getErrors() {
        return errors;
    }

    /**
     * @param errors the errors to set
     */
    public void setErrors(Map<String, String> errors) {
        this.errors = errors;
    }
}
